package com.coderg.gmall.oauth2.controller;

import com.coderg.gmall.common.result.Result;
import com.coderg.gmall.model.cart.CartInfo;
import com.coderg.gmall.oauth2.service.LoginService;
import com.coderg.gmall.oauth2.util.AuthToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author CoderG
 * @Date 2025/5/31 20:38
 **/
@RestController
@RequestMapping("/user")
public class LoginController {
    @Autowired
    LoginService loginService;
    @Autowired
    RedisTemplate redisTemplate;
    /**
     * 用户登录
     * @param username
     * @param password
     * @return
     */
    @PostMapping ("/login")
    public Result login(String username, String password, @RequestBody List<CartInfo> cartInfos){
        AuthToken login = loginService.login(username, password,cartInfos);
        return Result.ok(login);
    }
    /**
     * 用户退出登录
     * @param username
     * @param password
     * @return
     */
    @GetMapping("/logout")
    public Result logout(String username, String password){
        loginService.logout(username, password);
        return Result.ok("退出成功");
    }
}
